//
//  DCAPIManager.m
//  DCProject
//
//  Created by bigbing on 2019/4/22.
//  Copyright © 2019 bigbing. All rights reserved.
//

#import "DCAPIManager.h"
#import "NSObject+Category.h"


@implementation DCAPIManager

#pragma mark - 单列
+ (DCAPIManager *)shareManager {
    static DCAPIManager * _instance = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        _instance = [[[self class] alloc] init];
    });
    return _instance;
}


#pragma mark - 发送验证码
- (void)dc_requestSendCodeWithPhone:(NSString *)phone
                          WithPhone:(NSString *)type
                            success:(DCSuccessBlock)success
                           failture:(DCFailtureBlock)failture
{
    NSDictionary * params = @{@"phone":phone,
                              @"type":type};
    
    [DC_KeyWindow dc_disable];
    [[DCHttpClient shareClient] requestWithPath:@"/api/Connect/get_sms_captcha" params:params httpMethod:DCHttpRequestPost sucess:^(NSURLSessionDataTask * _Nonnull task, id  _Nonnull responseObject) {
        
        [DC_KeyWindow dc_enable];
        NSDictionary * dict = [responseObject mj_JSONObject];
        if (dict[DC_ResultCode_Key] && [dict[DC_ResultCode_Key] integerValue] == DC_Result_Success) {
            
            [SVProgressHUD showSuccessWithStatus:@"已发送"];
            if (success) {
                success(dict[@"result"]);
            }
            
        } else {
            
            [SVProgressHUD showErrorWithStatus:dict[DC_ResultMsg_Key]];
        }
        
    } failture:^(NSURLSessionDataTask * _Nonnull task, NSError * _Nonnull error) {
        
        [DC_KeyWindow dc_enable];
        if (failture) {
            failture(error);
        }
    }];
}


@end
